/*
 * @Author: ljk
 * @Date: 2023-06-03 10:50:02
 * @LastEditors: ljk
 * @LastEditTime: 2023-07-26 21:46:53
 * @Description: 类任务用于放进阻塞队列
 */
#pragma once
#include <string>
using namespace std;

class Task
{
public:
    Task()
    {
    }
    Task(int x, int y, char op, string name) : _x(x), _y(y), _op(op), _result(0), _name(name), _exitCode(0)
    {
    }
    void operator()()
    {
        switch (_op)
        {
        case '+':
            _result = _x + _y;
            break;
        case '-':
            _result = _x - _y;
            break;
        case '*':
            _result = _x * _y;
        break;
        case '/':
        {
            if (_y == 0)
                _exitCode = -1;
            else
                _result = _x / _y;
        }
        break;
        case '%':
        {
            if (_y == 0)
                _exitCode = -1;
            else
                _result = _x % _y;
        }
        break;
        default:
            break;
        }
    }
    std::string formatArg()
    {
        return _name + " | " + std::to_string(_x) + " " + _op + " " + std::to_string(_y) + " = ";
    }
    std::string formatRes()
    {
        return std::to_string(_result) + "(" + std::to_string(_exitCode) + ")";
    }
    ~Task()
    {
        //析构...
    }

private:
    int _x;
    int _y;
    char _op;
    string _name;
    int _result;
    int _exitCode;
};